/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.expert.dao.ExpertExperienceProblemSolutionDao;
import com.chlitina.store.modules.expert.dao.ExpertExperienceProblemSolutionDetailDao;
import com.chlitina.store.modules.expert.entity.ExpertExperienceProblemSolutionDetail;

/**
 * 专家推荐方案参数Service
 * @author liujiang
 * @version 2013-07-23
 */
@Component
@Transactional(readOnly = true)
public class ExpertExperienceProblemSolutionDetailService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ExpertExperienceProblemSolutionDetailService.class);
	
	@Autowired
	private ExpertExperienceProblemSolutionDetailDao expertExperienceProblemSolutionDetailDao;
	@Autowired
	private ExpertExperienceProblemSolutionDao expertExperienceProblemSolutionDao;
	
	public ExpertExperienceProblemSolutionDetail get(Long id) {
		return expertExperienceProblemSolutionDetailDao.findOne(id);
	}
	
	public ExpertExperienceProblemSolutionDetail getByPK(Long s_id, Long p_id) {
		DetachedCriteria dc = expertExperienceProblemSolutionDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq("expertExperienceProblemSolution.id", s_id));
		dc.add(Restrictions.eq("parameter.id", p_id));
		List<ExpertExperienceProblemSolutionDetail> list = expertExperienceProblemSolutionDetailDao.find(dc);
		if(list.size() > 0) {
			return list.get(0);
		}
		return new ExpertExperienceProblemSolutionDetail();
	}
	
	public List<ExpertExperienceProblemSolutionDetail> getByParent(Long pid) {
		DetachedCriteria dc = expertExperienceProblemSolutionDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq("expertExperienceProblemSolution.id", pid));
		return expertExperienceProblemSolutionDetailDao.find(dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ExpertExperienceProblemSolutionDetail e) {
		expertExperienceProblemSolutionDetailDao.save(e);
		expertExperienceProblemSolutionDao.refresh(e.getExpertExperienceProblemSolution());
	}
	
	@Transactional(readOnly = false)
	public void delete(ExpertExperienceProblemSolutionDetail e) {
		e.getExpertExperienceProblemSolution().getDetailList().remove(e);
		expertExperienceProblemSolutionDetailDao.delete(e);
	}
}
